/* Copyright (c) 2010, Peter Lényi */
/* Licensed under The BSD License. */

package gem.apps.fs.web;

import gem.apps.fs.engine.FileServer;
import gem.apps.fs.entities.FileMeta;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet class FileListPreServlet retrieves metadata about all files to be
 * displayed in a jsp and turns control over to the jsp.
 *
 * @author Peter Lényi
 * @version 20100425F
 */
public class FileListPreServlet extends HttpServlet
{
    private static final String ADDRESS_SUCCESS = "/file/list/jsp";
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // prepare resources
        FileServer fs = FileServer.getInstance();

        // execute logic
        List<FileMeta> filemetalist = fs.listFiles();

        // pass connection
        request.getSession().setAttribute("filemetalist", filemetalist);
        response.sendRedirect(getServletContext().getContextPath() + ADDRESS_SUCCESS);
    }
}
